package com.js.lib_common.mvp.presenter;


import com.js.lib_common.base.BasePresenter;
import com.js.lib_common.http.ApiCallback;
import com.js.lib_common.mvp.model.CommonBean;
import com.js.lib_common.mvp.view.ProductView;


public class ProductPresenter extends BasePresenter<ProductView> {
    public ProductPresenter(ProductView view) {
        attachView(view);
    }


    /**
     * @param userId     用户id
     * @param machineIds 需要入库的整机id，用英文逗号分隔+ 多个物料id的入库错误信息通过英文分号“;”分隔
     */
    public void checkIn(String userId, String machineIds) {
        if (userId==null||userId.isEmpty()){
            mvpView.onFailed("userId 为空");
            return;
        }
        mvpView.showLoading();
        addSubscription(apiStores.checkIn(userId, machineIds),
                new ApiCallback<CommonBean>() {

                    @Override
                    public void onSuccess(CommonBean response) {
                        if (response.isSuccess()) {
                            mvpView.onSuccess();

                        } else {
                            mvpView.onFailed(response.getMsg());
                        }

                    }

                    @Override
                    public void onFailure(String msg) {
                        mvpView.onFailed(String.format("checkIn fail %s", msg));
                    }

                    @Override
                    public void onFinish() {
                        mvpView.hideLoading();
                    }
                });
    }


    /**
     * @param userId     用户id
     * @param machineIds 整机Id
     * @param clientCode 客户提供的绑定编码，非必填
     */
    public void checkOut(String userId, String machineIds, String clientCode) {
        if (userId==null||userId.isEmpty()){
            mvpView.onFailed("userId 为空");
            return;
        }
        mvpView.showLoading();
        addSubscription(apiStores.checkOut(userId, machineIds, clientCode),
                new ApiCallback<CommonBean>() {

                    @Override
                    public void onSuccess(CommonBean response) {
                        if (response.isSuccess()) {
                            mvpView.onSuccess();
                        } else {
                            mvpView.onFailed(response.getMsg());
                        }

                    }

                    @Override
                    public void onFailure(String msg) {
                        mvpView.onFailed(String.format("checkOut fail %s", msg));
                    }

                    @Override
                    public void onFinish() {
                        mvpView.hideLoading();
                    }
                });
    }


}
